package hit.edu.zjc.Tool;

import hit.edu.zjc.DataClean.DataCleaner;
import hit.edu.zjc.DataIntegration.DataInteDis;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

public class ShowOutPut {
	
	public static void main(String[]args) throws FileNotFoundException
	{
		PrintStream ps=new PrintStream(new File(DataInteDis.DataDir,"NullValueSetTable.content").getAbsolutePath());  
		System.setOut(ps);
		//*
		Hashtable<Integer,HashSet<Integer>>SetTable=
				(Hashtable<Integer,HashSet<Integer>>)RWObject.ReadObject(
						new File(DataInteDis.DataDir,DataCleaner.CompletedNullValueSetTabelFileName).getAbsolutePath());
		ShowSetTable(SetTable);
		//*/
		
		/*
		 
		Hashtable<String,HashSet<Integer>>[] GramMap=(Hashtable<String,HashSet<Integer>>[])
				RWObject.ReadObject(
						new File(DataInteDis.DataDir,DataCleaner.CompletedNullValueGramMapFileName).getAbsolutePath());
		ShowGramMap(GramMap);
		*/
	}
	
	public static void show(String mes)
	{
		System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		System.out.println("????????????????????????????????????");
		System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		System.out.println(mes);
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		System.out.println("????????????????????????????????????");
		System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		System.out.flush();
	}
	
	

	public static void ShowSetList(ArrayList<HashSet<Integer>> setlist)
	{
		System.out.println("SetList size:"+setlist.size());
		for(int i=0;i<setlist.size();i++)
		{
			System.out.println(i+"th:");
			HashSet<Integer> set=setlist.get(i);
			Iterator<Integer> it=set.iterator();
			while(it.hasNext())
			{
				Integer id=it.next();
				System.out.print(id+" ,");
			}
			System.out.println();
		}
	}
	
	
	public static void ShowGramMap(Hashtable<String,HashSet<Integer>>[] GramMap)
	{
		for(int i=0;i<GramMap.length;i++)
		{
			System.out.println("The "+i+"th GramMap:");
			Enumeration<String> e=GramMap[i].keys();
			ArrayList KeyList = Collections.list(e);
			Collections.sort(KeyList); 
			for(int j=0;j<KeyList.size();j++)
			{
				HashSet<Integer> set=GramMap[i].get(KeyList.get(j));
				Integer[] value_array=new Integer[set.size()];
				set.toArray(value_array);
				List<Integer> value_list=Arrays.asList(value_array);
				Collections.sort(value_list);
				System.out.println("Key:"+KeyList.get(j));
				System.out.print("Set:");
				for(int listindex=0;listindex<value_list.size();listindex++)
					System.out.print(value_list.get(listindex)+",");
				System.out.println();				
			}
		}

	}

	public static void ShowSetTable(Hashtable<Integer,HashSet<Integer>> SetTable)
	{
		System.out.println("ShowSetTable");
		System.out.println("Size:"+SetTable.size());
		Enumeration<Integer> e=SetTable.keys();
		while(e.hasMoreElements())
		{
			Integer key=e.nextElement();
			HashSet<Integer>set=SetTable.get(key);
			System.out.print(key+":");
			Iterator<Integer> it=set.iterator();
			while(it.hasNext())
			{
				Integer id=it.next();
				System.out.print(id+" ,");
			}
			System.out.println();
		}
	}
	
}
